<template>
	<div id="message_add_edit">
		<div class="form">
			<div class="row">
				<label class="label">
					<span>*</span>
					消息标题
				</label>
				<el-input v-model="param.title" id="title" style="width: 3rem;" maxLength="30" 
					      placeholder="" clearable></el-input>
				&nbsp;
				<span class="tips">支持1-30个汉字，字母，数字，符号输入</span>
			</div>
			
			<div class="row">
				<label class="label">
					<span>*</span>
					消息内容
				</label>
				<el-input type="textarea" class="textarea" :rows="5" id="content" v-model="param.content"
					      placeholder="" maxLength="300" style="width: 6rem;">
				</el-input>
				<div class="tips" style="padding-left: 1.1rem;">
					支持1-300个汉字，字母，数字，符号输入
				</div>
			</div>
			
		</div>
		<div class="btn_div">
			<div class="btn_sure" @click="sure(0)">保 存</div>
			<div class="btn_sure" @click="sure(1)">保存并发送</div>
			<div class="btn_cancel" @click="cancel()">取 消</div>
		</div>
	</div>
</template>

<script>
var vm,dict;
var param = {
	title : "",
	content : "",
	type : 0,
	isPublish: 0,
	receiverType: 0,
	_wait : ""
}
export default {
	data : function() {
		return {
			param : {},
			isAdd: true
		}
	},
	methods : {
		init : function(message) {
			if(message) {
				vm.param = tool.clone(message);
				vm.isAdd = false;
			} else {
				vm.param = tool.clone(param);
				vm.isAdd = true;
			}
		},
		cancel : function() {
			vm.$emit('cancel');
		},
		sure : function(isPublish) {
			//验证规则
			var rules = [{
				judge : vm.param.title,
				focus : $("#message_add #title"),
				tips : tips.blank
			},{
				judge : vm.param.content,
				focus : $("#message_add #content"),
				tips : tips.blank
			}];
			
			if(!tool.validate(rules)) {
				return;
			}
			//设置更新状态
			vm.param.isPublish = isPublish;
			let message = (isPublish==1? "消息发送成功" : "消息保存成功");
			//新增或编辑操作
			if(vm.isAdd) {
				api.messageAdd(vm.param).then(function(data) {
					tool.message({ showClose: true, message, type: 'success' });
					vm.$emit('cancel');
					vm.$emit('ok');
				});
			} else {
				api.messageUpdate(vm.param).then(function(data) {
					tool.message({ showClose: true, message, type: 'success' });
					vm.$emit('cancel');
					vm.$emit('ok');
				});
			}
		},
	},
	created : function() {
		vm = this;
	}
}
</script>
<style lang="scss">
#message_add_edit {
	.el-textarea__inner {
		font-size: 0.16rem;
		font-family: "微软雅黑";
	}
}
</style>
<style scoped src="@/style/module/dialog_button.css"></style>
<style scoped>
	.form {
		font-size: 0.16rem;
		color: #666666;
	}
	.tips {
		font-size: 0.14rem;
		color: #999999;
	}
	.row {
		line-height: 0.36rem;
		padding: 0.07rem 0;
	}
	.label {
		width: 0.9rem;
		display: inline-block;
		text-align: right;
		margin-right: 0.12rem;
		vertical-align: top;
	}
	.label>span {
		color: red;
		display: inline-block;
		width: 0.1rem;
		position: relative;
		top: 0.02rem;
	}
	.textarea {
		width:5rem;
		padding: 0.07rem 0 0rem 0;
	}
</style>